﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;

namespace Bouyei.Geo.GeoParsers.Parser
{
    using Dbf;

    /// <summary>
    /// 摘自网上开源收集整理,*.dbf文件解析
    /// </summary>
    public class DbfParser
    {

        private Encoding encoding = Encoding.UTF8;
        public DbfParser(Encoding encoding) {
            this.encoding = encoding;
        }

        // Read an entire standard DBF file into a DataTable
        public DataTable FromReader(string dbfFile)
        {
            using (DbfReader reader = new DbfReader(dbfFile, encoding))
            {
                return reader.Reader();
            }
        }

        public int ToWriter(string dbfFile, DataTable data)
        {
            using (DbfWriter writer = new DbfWriter(dbfFile, encoding))
            {
                return writer.Writer(data);
            }
        } 

        public int ToWriter<T>(string dbfFile,List<T> list)
        {
            using (DbfWriter writer = new DbfWriter(dbfFile, encoding))
            {
                return writer.Writer<T>(list);
            }
        }
    }
}
